package com.box2dwrapper.object
{
	import Box2D.Dynamics.Joints.*;
	
	import flash.utils.*;
	
	dynamic public class Joint extends Proxy
	{
		
		public static const DISTANCE:String = "distance";
		public static const REVOLUTE:String = "revolute";
		public static const PRISMATIC:String = "prismatic";
		public static const PULLEY:String = "pulley";
		public static const GEAR:String = "gear";
		
		public var type:String;
		public var joint:b2Joint;
		public var jointDef:*;
		
		public function Joint(jointType:String = null)
		{
			type = jointType;
			createNewJoint();
		}
		
		override flash_proxy function getProperty(name:*):*
		{
			return jointDef[name];
		}
		
		override flash_proxy function setProperty(name:*, value:*):void 
		{
			jointDef[name] = value;
        }
        
        override flash_proxy function callProperty(name:*, ... args):* 
        {
        	name = String(name);
        	if(name == "initialize") name = "Initialize";
        	return jointDef[name].apply(jointDef, args);
        }
        
        private function createNewJoint():void
		{
			switch(type)
			{
				case "distance":				
				jointDef = new b2DistanceJointDef();
				break;
				
				case "revolute":
				jointDef = new b2RevoluteJointDef();				
				break;
				
				case "prismatic":
				jointDef = new b2PrismaticJointDef();	
				break;
				
				case "pulley":
				jointDef = new b2PulleyJointDef();
				break;
				
				case "gear":
				jointDef = new b2GearJointDef();
				break;
			}
		}

	}
}